home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!wemccaug
- From: wemccaug@prairienet.org (Wendy E. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: "new" creams data structure -- why?
- Date: 2 Feb 1996 11:51:43 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4estsf$2v@vixen.cso.uiuc.edu>
- References: <4erl1i$oas@news1.usa.pipeline.com>
- Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, grantp@usa.pipeline.com (Pete) says:
-
- >On Feb 01, 1996 23:08:16 in article <"new" creams data structure -- why?>,
- >'<73067.3334@compuserve.com>' wrote:
- >
- >
- >>
- >>dear experts: why would the following line alloc memory where there is
- >>insufficient space for it? when i memcpy to clear the string, it wipes
- >out
- >>a data structure i needed. the line is
- >>
- >>char* somestring = new char [300];
- >>
- >>when it's my fault i can deal with it, but how do i prevent this? or is
- >it
- >>a scoping problem or something?
- >>
- >>many thanks for any ideas.
- >
- >If operator new fails -- assuming it's the default
- >global one -- it returns 0. If you don't test for it, then it's
- >your fault. But I suspect the problem is elsewhere.
- >
- All true, but then this is why _new_handler exists: to point to your
- 'new' handler if you're not happy with the default one. Just say:
- set_new_handler(my_new_handler);
- where 'my_new_handler' is your cunstomized function to output diagnostics
- when it gets invoked by 'new' upon exhaustion of available memory. Either
- by using #include's or declaring yourself, you must have:
-
- typedef void (*FP)(); // function-ptr type, FP
-
- extern FP set_new_handler(FP);
-
- and your routine should be prototyped: void my_new_handler();
-
- FInally, your diagnostic routine should have access (via globals, e.g.)
- to the variables you want to diagnose.
-
- -- Scott
-
-